<!--
 * Copyright ©
 * #  
 * @author: zw
 * @date: 2021-11-26 
 -->

<template>
  <el-pagination
    @size-change="sizeChange"
    @current-change="currentChange"
    :page-sizes="sizes"
    :current-page="pagination.pageIndex"
    :page-size="pagination.pageSize"
    :total="pagination.total"
    :layout="pagination.layout"
  ></el-pagination>
</template>

<script lang="js">
import { defineComponent, computed } from "vue";
export default defineComponent({
  name: "pagination",
  props: {
    options: {
      required: true,
      type: Object,
    }
  },
  setup(props, { emit, slots }) {
    const sizeChange = (...arg) => {
      emit('sizeChange', ...arg);
    }
    const currentChange = (...arg) => {
      emit('currentChange', ...arg);
    }
    const pagination = computed(() => {
      const opts = {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
        sizes: [10, 20, 50, 100],
        layout: "total, sizes, prev, pager, next, jumper",
      };
      for(let key in props.options) {
        if (props.options[key] instanceof Function) break
        else opts[key] = props.options[key];
      }
      return opts;
    });
    return {
      sizeChange,
      currentChange,
      pagination
    };
  },
});
</script>

<style lang="css" scoped></style>
